#include "queue.h"
#include "length.h"

void QueueInit(queue* source,char* buff,unsigned int baseSize,unsigned int number)
{
	source->bSize = baseSize;
	source->num = number;
	source->size = baseSize*number;
//	source->base = (char*)Kmalloc(source->size);
	source->base = buff;
	source->head = 0;
	source->tail = 0;
	source->nSize = 0;
//	SIZE = source->size;
}
void QueueFree(queue* source)
{
//	free(source->base);
//	SIZE = 0;
}
void QueuePush(queue* source,void* from)
{
	if(source->nSize >= source->num) return ;
	char* buff = (char*)from;
	unsigned int i;
	for(i = 0; i <source->bSize ; i++)
	{
		*(source->base + ((source->head + i) % source->size)) = *(buff+i);
	}
	source->head = (source->head + source->bSize) % source->size;
	source->nSize++;
}
void QueuePop(queue* source,void* target)
{
	if(source->nSize == 0) return;
	char* buff = (char*)target;
	unsigned int i;
	for(i = 0 ; i < source->bSize ; i++)
	{
		*(buff+i) = *(source->base +((source->tail +i) % source->size));
	}
	source->tail = (source->tail + source->bSize) % source->size;
	source->nSize--;
}
int QueueEmpty(queue* source)
{
	if(source->nSize == 0)return 1;
	return 0;
}
inline _ptlong QueueSize(queue* source)
{
  return source->nSize;
}
